/*******************************************************************************
 * Copyright (c) 2004 Andrei Loskutov.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the BSD License
 * which accompanies this distribution, and is available at
 * http://www.opensource.org/licenses/bsd-license.php
 * Contributor:  Andrei Loskutov - initial API and implementation
 *******************************************************************************/
package de.loskutov.anyedit.popup.actions;

import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;

import com.googlecode.eclipse.navigatorext.Activator;

/**
 * 
 */
public class AbstractAction extends com.googlecode.eclipse.navigatorext.actions.AbstractAction {

    protected AbstractEditor editor;

    protected void setEditor(AbstractEditor editor) {
        if (getEditor() != null) {
            getEditor().dispose();
        }
        this.editor = editor;
    }

    protected AbstractEditor getEditor() {
        return editor;
    }

    protected AbstractEditor createActiveEditorDelegate(IEditorPart editorPart) {
        return new AbstractEditor(editorPart);
    }

    protected AbstractEditor createActiveEditorDelegate() {
        return new AbstractEditor(getActiveEditor());
    }

    public static IEditorPart getActiveEditor() {
        IWorkbenchWindow window = Activator.getDefault().getWorkbench().getActiveWorkbenchWindow();
        if (window != null) {
            IWorkbenchPage page = window.getActivePage();
            if (page != null) {
                return page.getActiveEditor();
            }
        }
        return null;
    }
}
